﻿#region File Description
/*-----------------------------------------------------------------------------
 Author: Jose Antonio Gallego
 Date: 24/10/2011
 
 License: Ms-PL
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.

 The example companies, organizations, products, domain names,
 e-mail addresses, logos, people, places, and events depicted
 herein are fictitious.  No association with any real company,
 organization, product, domain name, email address, logo, person,
 places, or events is intended or should be inferred.
-----------------------------------------------------------------------------*/
#endregion

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Device.Location;
using System.IO.IsolatedStorage;

namespace Zombsquare.Models
{
    public class MainDataContext : INotifyPropertyChanged
    {
        #region campos privados

        private ObservableCollection<PushpinModel> _pushpins = new ObservableCollection<PushpinModel>();

        #endregion

        #region propiedades        

        /// <summary>
        /// Retorna o establece si los datos de localiazación han sido cargados
        /// </summary>
        public bool DataLoaded { get; set; }

        /// <summary>
        /// Indica el punto al que navegar
        /// </summary>
        public PushpinModel NavigateTo { get; set; }

        /// <summary>
        /// Obtiene o establece la localización actual
        /// </summary>
        public GeoCoordinate CurrentLocation = new GeoCoordinate(41.652196, -4.728321);
       
        /// <summary>
        /// Obtiene la colección de pushpins.
        /// </summary>
        public ObservableCollection<PushpinModel> Pushpins
        {
            get { return _pushpins; }
        }

        /// <summary>
        /// Contiene las dosis de Zbrex disponibles
        /// </summary>
        public int DosisZbrex
        {
            get
            {
                int dosis;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue<int>("zbrex", out dosis);
                return dosis;
            }
            set
            {
                if (value < 10)
                {
                    IsolatedStorageSettings.ApplicationSettings["zbrex"] = value;
                    NotifyPropertyChanged("DosisZbrex");
                }
            }
        }

        #endregion

        #region metodos públicos

        /// <summary>
        /// Carga las coordenadas de los zombies y civiles
        /// </summary>
        public void LoadData()
        {
            Pushpins.Clear();
            DataManager dataManager = new DataManager();            

            _pushpins = dataManager.Select();

            DataLoaded = true;
        }


        #endregion

        //TODO: how to get a Bing Maps Key: http://msdn.microsoft.com/en-us/library/ff428642.aspx
        /// <value>ID registrado del control Bing Maps que además da acceso a los servicios de Bing Maps.</value>        
        public string IdBingMapsApi = "AmFVMc9z6hq2Dz42-kltAmCkKc27NUntOxDBvIrwm6QMQooO6FgUkUX-9IoAgsWa";
        
        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

    }
}
